Cognitive Brownbag

Holly Zaharchuk

February 19, 2020

What is R Markdown?

  • Markup language
  • R Markdown != R

Parts of a Markdown document

  1. YAML header
  2. Markdown language
  3. Code chunks

YAML header

Global options for outputs/formatting

YAML example

Markdown

Plain text formatting allows for conversion to multiple document types

Markdown example

Chunks

# This is a chunk of R code that adds an image
knitr::include_graphics("images/example_chunk.png")

Creating output

Output types

  • PDF: requires \(\LaTeX\) to compile (see TinyTeX distribution)
  • HTML
  • Microsoft Office (Word/Powerpoint)

YAML specification

  • Use output argument in YAML header
  • Pay attention to indentation and colons
  • Press knit button or CMD/CRTL-Shift-K

Render

  • Render file in console: rmarkdown::render(file, output_format = c(X, Y)...)
  • Option to create PDF from HTML: pagedown::chrome_print(file)

Using templates

  • Built-in templates
  • Templates from R packages
  • User-defined templates

Built-in templates

  • Presentations
    • ioslides and Slidy for HTML
    • Beamer for PDF
  • Shiny documents and presentations (interactive)

R packages

User-defined templates

\(\LaTeX\) templates LaTeX example

User-defined templates

Word Document Word example

Formatting

  • YAML parameters and references
  • \(\LaTeX\) and CSS code in Markdown
  • Template documents

YAML parameters

YAML references

These files go in the same place as your .Rmd

\(\LaTeX\) and CSS

  • \(\LaTeX\) with PDFs
    • Packages
    • Symbols: here and here
    • Type-setting
  • CSS with HTML

\(\LaTeX\)

Examples from my stats homework

Packages Calls

\(\LaTeX\)

LaTeX example output

CSS/HTML

Examples from my Psychonomics poster

CSS formatting example HTML formatting example

Updating template documents

# Make dataframe with installed packages
pkgs <- installed.packages() %>%
  as.data.frame()

# Pull posterdown package 
pstr <- pkgs %>% 
  select(Package, LibPath, Version, Depends, Imports) %>%
  dplyr::filter(Package == "posterdown")

# Make table
kable(pstr) %>%
  kable_styling(bootstrap_options = "condensed", 
                font_size = 20)
Package LibPath Version Depends Imports
posterdown /Library/Frameworks/R.framework/Versions/3.5/Resources/library 1.0 NA pagedown, rmarkdown, yaml

Updating template documents

  • Save the original
  • Make one change at a time

Helpful tidbits

  • date: "“February 13, 2020”"

Random pieces of information

R Stuff